using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace FCalendar
{
    static class Program
    {

        public static MainForm mainForm;
        public static FormBox fbox;
        public static FormOption foption;

        private static bool _isToday;
        public static bool IsToday {
            get
            {
                return _isToday;
            }
            set
            {
                _isToday = value;
                mainForm.toolStripMenuItem5.Checked = value;
                fbox.todayToolStripMenuItem.Checked = value;
            }
        }

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            foption = new FormOption();
            mainForm = new MainForm();
            fbox = new FormBox();
            
            // set today
            Program.IsToday = true;

            // Set for hybernate
            Microsoft.Win32.SystemEvents.PowerModeChanged += new Microsoft.Win32.PowerModeChangedEventHandler(SystemEvents_PowerModeChanged);

            // Set timer for end of today to change date
            TimeSpan t = DateTime.Today.AddDays(1) - DateTime.Now;
            mainForm.timer1.Interval = (int)t.TotalMilliseconds;

            string[] s = Environment.GetCommandLineArgs();
            mainForm.showForm = false;
            if ((s.Length > 1 && s[1] == "-box") || mainForm.boxToolStripMenuItem.Checked)
            {
                mainForm.ShowDate();
                mainForm.showBox = true;
            }
            Application.Run(mainForm);
        }

        static void SystemEvents_PowerModeChanged(object sender, Microsoft.Win32.PowerModeChangedEventArgs e)
        {
            if (e.Mode == Microsoft.Win32.PowerModes.Resume)
            {
                if (IsToday)
                    mainForm.monthCalendar1.SetDate(DateTime.Now);
            }
        }
    }
}